package com.longrise.android.byjk.plugins.tabthird.invoice;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.R;
import com.longrise.common.utils.AppUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/20.
 * 消费记录adapter
 */

class ConsumeReportRcvAdapter extends BaseQuickAdapter<EntityBean, BaseViewHolder>{

    private List<EntityBean> mListBeans = new ArrayList<>();

    public ConsumeReportRcvAdapter() {
        super(R.layout.item_consume_report_rcv);
    }

    public void refreshData(EntityBean[] beans) {
        mListBeans.clear();
        for (EntityBean bean : beans) {
            mListBeans.add(bean);
        }
        setNewData(mListBeans);
    }

    @Override
    protected void convert(BaseViewHolder helper, EntityBean item) {

        final View convertView = helper.getConvertView();
        final TextView tv_course_name = helper.getView(R.id.tv_course_name);
        helper.setText(R.id.tv_course_name,item.getString("subject"))
                .setText(R.id.tv_consume_price,"-"+item.getString("total_fee"))
                .setText(R.id.tv_course_time,item.getString("endtime"));

        tv_course_name.post(new Runnable() {
            @Override
            public void run() {
                int lineCount = tv_course_name.getLineCount();
                ViewGroup.LayoutParams layoutParams = convertView.getLayoutParams();
                if (lineCount == 2) {
                    layoutParams.height = AppUtil.dip2px(99);
                } else {
                    layoutParams.height = AppUtil.dip2px(73);
                }
                convertView.setLayoutParams(layoutParams);
            }
        });
    }
}
